package com.baofu.paycore.common.utils;

import com.baofu.paycore.common.exception.ManagerErrorCode;
import com.baofu.paycore.common.exception.PayCoreBaseException;
import com.baofu.paycore.common.exception.ServiceErrorCode;
import com.baofu.paycore.service.facade.enums.PayCoreErrorCode;
import com.system.commons.exception.BizServiceException;
import com.system.commons.exception.CommonErrorCode;

/**
 * 支付错误码工具
 *
 * User: xin deng  Date: 2017/4/26 ProjectName: paycore Version: 1.0
 */
public class PayCoreErrorCodeUtil {

    /**
     * 支付状态处理
     *
     * @param payCoreBaseException      异常
     * @return                          boolean
     */
    public static boolean payStatusHandler(PayCoreBaseException payCoreBaseException){

        String errorCode = payCoreBaseException.getErrorCode().getErrorCode();
        PayCoreErrorCode payCoreErrorCode = PayCoreErrorCode.getByCode(errorCode);
        switch (payCoreErrorCode){
            case PRE_AUTH_ORDER_NO_EXIST:
                return true;
            case PRE_AUTH_ORDER_NO_SUC:
                return true;
            case OVERRUN_CANCEL_AMOUNT:
                return true;
            case AMT_IS_NOT_IN_CONFORMITY:
                return true;
            case EVENT_NO_NOT_EXIST:
                return true;
            case OLD_ORDER_IS_NOT_EXISTED:
                return true;
            case FEE_AMT_NOT_MORE_PAY_AMT:
                return true;
            case FREEZE_ORDER_NO_EXIST:
                return true;
            case FREEZE_ORDER_NO_SUC:
                return true;
            case OVERRUN_CONFIRM_AMOUNT:
                return true;
            case FREEZE_ORDER_NO_FREEZECODE:
                return true;
            default:
                return false;
        }
    }

    /**
     * 支付状态处理
     *
     * @param exception                 异常
     * @return                          boolean
     */
    public static boolean payStatusHandler(BizServiceException exception){

        String errorCode = exception.getErrorCode().getErrorCode();

        if (CommonErrorCode.PARAMETER_VALID_NOT_PASS.getErrorCode().equals(errorCode)){
            return true;
        }
        if (PayCoreErrorCode.BIZ_FEE_ACCOUNT_NOT_NULL.getErrorCode().equals(errorCode)){
            return true;
        }
        if (ManagerErrorCode.AMT_ERROR.getErrorCode().equals(errorCode)){
            return true;
        }
        if (ManagerErrorCode.FEE_AMT_NOT_MORE_PAY_AMT.getErrorCode().equals(errorCode)){
            return true;
        }
        if (ServiceErrorCode.PROCESS_ORDER_ERROR.getErrorCode().equals(errorCode)){
            return true;
        }
        PayCoreErrorCode payCoreErrorCode = PayCoreErrorCode.getByCode(errorCode);
        switch (payCoreErrorCode){
            case ORIG_ORDER_NOT_EXIST:
                return true;
            case AMT_IS_NOT_IN_CONFORMITY:
                return true;
            case PRE_AUTH_ORDER_NO_EXIST:
                return true;
            case PRE_AUTH_ORDER_NO_SUC:
                return true;
            case OVERRUN_CONFIRM_AMOUNT:
                return true;
            case FEE_AMT_NOT_MORE_PAY_AMT:
                return true;
            case EVENT_NO_NOT_EXIST:
                return true;
            default:
                return false;
        }
    }
}
